<?
class ManageSpam extends Module{
	function ManageSpam($row){
		Module::Module($row);
		
		if(User::is_admin()){
			$cmd=Url::get('cmd');
			
			switch($cmd){				
				case 'delete_email':
					$id = (int)Url::get('id',0);
					if($id)
						DB::delete("spam_mail","id=$id");
					
					Url::redirect_current(array('cmd'=>'email_list'));
					
					break;
				case 'delete_content':
					$id = (int)Url::get('id',0);
					if($id)
						DB::delete("spam_content","id=$id");
					
					Url::redirect_current();
					break;
				case 'active_content':
					$id = (int)Url::get('id',0);
					if($id){
						DB::query("UPDATE spam_content SET status=1 WHERE id=$id");
						DB::query("UPDATE spam_content SET status=0 WHERE id!=$id");
					}
					
					Url::redirect_current();
					break;
				case 'deactive_content':
					$id = (int)Url::get('id',0);
					if($id){
						DB::query("UPDATE spam_content SET status=0 WHERE id=$id");
					}
					
					Url::redirect_current();
					break;
				case 'active_email':
					$id = (int)Url::get('id',0);
					if($id){
						DB::query("UPDATE spam_mail SET status=1 WHERE id=$id");
					}
					
					Url::redirect_current(array('cmd'=>'email_list'));
					break;
				case 'deactive_email':
					$id = (int)Url::get('id',0);
					if($id){
						DB::query("UPDATE spam_mail SET status=0 WHERE id=$id");
					}
					
					Url::redirect_current(array('cmd'=>'email_list'));
					break;
				case 'reset_email':
					$id = (int)Url::get('id',0);
					if($id){
						DB::query("UPDATE spam_mail SET spam_id=0 WHERE id=$id");
					}
					
					Url::redirect_current(array('cmd'=>'email_list'));
					break;
				case 'active_all_email':
					DB::query("UPDATE spam_mail SET status=1");
					Url::redirect_current(array('cmd'=>'email_list'));
					break;
				case 'deactive_all_email':
					DB::query("UPDATE spam_mail SET status=0");
					Url::redirect_current(array('cmd'=>'email_list'));
					break;
					
				
				case 'edit_email':
					require_once 'forms/EditEmail.php';
					$this->add_form(new EditEmailForm());
					break;
				case 'add_email':
					require_once 'forms/AddEmail.php';
					$this->add_form(new AddEmailForm());
					break;
				case 'email_list':
					require_once 'forms/ManageEmail.php';
					$this->add_form(new ManageEmailForm());
					break;	
				case 'edit_content':
					require_once 'forms/EditContent.php';
					$this->add_form(new EditContentForm());
					break;
				case 'add_content':
					require_once 'forms/AddContent.php';
					$this->add_form(new AddContentForm());
					break;
				default: 
					require_once 'forms/ManageSpam.php';
					$this->add_form(new ManageSpamForm());
					break;
			}
		}
		else{
			Url::access_denied();
		}
	}
}
?>